<template>
  <view v-if="visible" class="modal-overlay">
    <view class="content">
      <view class="modal-header">
        <text>{{ title }}</text>
      </view>
      <view class="modal-body">
		  <p class="modal-text">企业号</p>
		  <view class="input-box" >
		  <input  type="text" class="input-box" style="text-align: left;" v-model="inputValue"/>
		  </view>
		  <p class="modal-text">联系号码</p>
		  <view class="input-box" >
		  <input  type="text" class="input-box" style="text-align: left;" v-model="periodValue"/>
		  </view>
		  <p class="modal-text">账号密码</p>
		  <!-- <textarea class="input-text"></textarea> -->
		  <input  type="text" class="input-box" style="text-align: left;" v-model="textareaContent"/>
		 <!-- <div>
		  	<textarea  v-if="!ismodelshow && !ismodelperiod"  rows="4" cols="50" class="reason-all"  v-model="textareaContent"/>
		  </div> -->
		  </view>
		  <view class="modal-footer">
		  		  <span @click="closeShow" class="quxiao" >取消</span><span class="yuyue" @click="addCilck">确定</span>
		  </view>
    </view>
  </view>
</template>

<script>
export default {
	 props: {
	   },
  data() {
    return {
      visible: false,
      title: '预约',
      inputValue: '',
	  selectedValue: '',
	        options: [
	          { value: 'option1', label: '选项1' },
	          { value: 'option2', label: '选项2' },
	          // ...更多选项
	        ],
	  selectedDate: '' ,// 存储选中的日期,
	  ismodelshow:false,//时间
	  successStartTime:'',
	  successEndTime:'',
	  showSlider: false,
	  ismodelperiod:false,//时间段
	  periodValue:'',
	  req:{
		  name:'',
		  phone:'',
		  password:'',
		  subaccountId:0
	  },
	  textareaContent:'',
    };
  },
  methods: {
	  addCilck(){
		  if(!this.inputValue){
		     uni.showToast({
		             title: '请填写账号名称',
		             icon: 'none',
		         });
		     return; // 如果为空，则不执行后续操作
		  }else if(!this.periodValue){
			  uni.showToast({
			          title: '请填写联系号码',
			          icon: 'none',
			      });
			  return; // 如果为空，则不执行后续操作
		  }else if(!this.textareaContent){
		  			  uni.showToast({
		  			          title: '请填写账号密码',
		  			          icon: 'none',
		  			      });
		  			  return; // 如果为空，则不执行后续操作
		  }else if(this.periodValue.length!==11){
			  uni.showToast({
			          title: '手机号长度不正确',
			          icon: 'none',
			      });
			      return; // 如果长度超过11位，则不执行后续操作
		  }
		  
		  //	账号名称
		  this.req.name=this.inputValue;
		  //	联系号码
		  this.req.phone=this.periodValue;
		  //	账号密码
		  this.req.password=this.textareaContent;
		  //	父账号id
		  this.req.subaccountId=this.userId;
		  this.$emit('add-item',this.req);
		  this.visible = false;
	  },
	  periodshow(){
		  this.ismodelperiod = true;
		  this.showSlider = true;
	  },
	  show(data){
		  this.ismodelshow = data;
	  },
	  showItem(){
		  console.log(this.phone);
	  },
	  confirm(data){
		 // 这里是处理从子组件接收到的数据的代码
		 if(data.year==undefined){
			  this.periodValue=data.half;
			  
		 }else{
			this.inputValue=data.year+'-'+data.month+'-'+data.day; 
		 }
		this.ismodelshow = false;
		this.ismodelperiod=false;
	  },
	  closeDate(){
		  this.ismodelshow = false;
	  },
	  closeShow(){
		  this.visible = false;
	  },
	  modelshow(){
		 this.showSlider = true;
		 this.ismodelshow = true;
		  // 移除 <textarea> 的焦点
	  },
    showModal(title, callback,data) {
      this.title = title;
      this.callback = callback;
      this.visible = true;
      // 可以在这里重置 inputValue，如果需要的话
	  if(!data){
		  this.periodValue='';
		  this.textareaContent='';
		  this.inputValue = '';
	  }else if(data.type==="修改"){
		  this.periodValue=data.phone;
		  this.textareaContent=data.password;
		  this.inputValue = data.enterpriseId;
	  }
	  
    },
    closeModal() {
      this.visible = false;
      if (this.callback && typeof this.callback.onCancel === 'function') {
        this.callback.onCancel();
      }
    },
    confirmInput() {
      this.visible = false;
      if (this.callback && typeof this.callback.onConfirm === 'function') {
        this.callback.onConfirm(this.inputValue);
      }
    }
  }
};
</script>

<style scoped>
@import "accountModel.css";
</style>